package cn.imvc.app.controllers.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;

import cn.imvc.app.entities.Group;
import cn.imvc.app.models.GroupModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;
import cn.imvc.data.domain.ViewRequest;

public class GroupControllerImpl implements GroupController {
	
	public Page<Group> page;
	public ViewRequest viewRequest;
	public Group group;
	public int id;
	public int[] ids;
	@Autowired
	private GroupModel groupModel;


	public void setViewRequest(ViewRequest viewRequest) {
		this.viewRequest = viewRequest;
	}

	public void setGroup(Group group) {
		this.group = group;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setIds(int[] ids) {
		this.ids = ids;
	}

	public String search() {
		return "group/search";
	}

	public String index() {
		page=groupModel.find(viewRequest);
		return "group/index";
	}

	public String show() {
		group=groupModel.get(id);
		return "group/show";
	}
	public String detail(){
		group=groupModel.get(id);
		return "group/detail";
	}
	public String editNew() {
		return "group/editNew";
	}

	public String create() {
		groupModel.save(group);
		return Render.json(new DialogBean("200", "创建成功","group", "closeCurrent"));
	}

	public String edit() {
		group=groupModel.get(id);
		return "group/edit";
	}

	public String update() {
		groupModel.update(id, group);
		return Render.json(new DialogBean("200", "修改成功","group", "closeCurrent"));
	}

	public String destroy() {
		groupModel.delete(id);
		return Render.json(new DialogBean("200", "删除成功","group"));
	}

	public String destroyBatch() {
		groupModel.deleteBatch(ids);
		return Render.json(new DialogBean("200", "删除成功","group"));
	}

}
